package Stream;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class StreamDemo {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("林");
        list.add("张");
        list.add("柳");
        list.add("王");
        list.add("张1");
        list.add("张2");

        ArrayList<String> list2 = new ArrayList<>();

        for (String s:list){
            if (s.startsWith("张")){
                list2.add(s);
            }
        }
        System.out.println(list2);

        for (String s:list2){
            System.out.println(s);
        }

        System.out.println("--------------------------------------------------------------");

       list.stream().filter(s->s.startsWith("张")).filter(s->s.length()==2).forEach(s-> System.out.println(s));
//        list.stream().filter(s->s.startsWith("张")).filter(s->s.length()==2).forEach(System.out::println);


        Stream<String> s1=list.stream().filter(s->s.startsWith("张")).filter(s->s.length()==2);
        List<String> zhanglist = s1.collect(Collectors.toList());
        System.out.println(zhanglist);
    }
}
